function Fig=PlotNiceTabel(Table,Fig)
%%
[YVarNum,XVarNum]=size(Table);
%% Check Figure handel
if nargin<2
    a=figure();
    Fig.Fig=a;
end
if isnumeric(Fig)
    Temp=Fig;
    clear Fig
    Fig.Fig=Temp;
end
%% Text, Title and Labels
if ~isfield(Fig,'TextSize')
    Fig.TextSize=14;
end
if ~isfield(Fig,'TextStyle')
    Fig.TextStyle='%3.2e';
end
if ~isfield(Fig,'Title')
    Fig.Title=Table.Properties.Description;
end
if ~isfield(Fig,'YLabel')
    Fig.YLabel='';
end
if ~isfield(Fig,'XLabel')
    Fig.XLabel='';
end
if ~isfield(Fig,'XVarName')
    Fig.XVarName=Table.Properties.VariableNames;
end
if ~isfield(Fig,'YVarName')
    Fig.YVarName=Table.Row;
end
if ~isfield(Fig,'YVarNameAngel')
    Fig.YVarNameAngel=0;
end
if ~isfield(Fig,'XVarNameAngel')
    Fig.XVarNameAngel=0;
end

%% Pos
if ~isfield(Fig,'TypeValues')
    Fig.TypeValues=true;
end
if Fig.TypeValues
    if ~isfield(Fig,'TypeValuesPos')
        [Fig.TypeValuesPos{1},Fig.TypeValuesPos{2}]=meshgrid(0.5:1:XVarNum,0.5:1:YVarNum);
        try
            Fig.TypeValuesPos{3}=max(max(Table.Variables));
        catch
            Fig.TypeValuesPos{3}=1;
        end
    end
    if ~isfield(Fig,'Text')
        Fig.Text=cell(YVarNum,XVarNum);
        for i=1:YVarNum
            for j=1:XVarNum
                if isstring(Table(i,j).Variables)
                    Fig.Text{i,j}=Table(i,j).Variables;
                elseif iscell(Table(i,j).Variables)
                    Fig.Text(i,j)=Table(i,j).Variables;
                else
                    Fig.Text{i,j}=num2str(Table(i,j).Variables,Fig.TextStyle);
                end
            end
        end
    end
end

%% Color Map and Colorbar
if ~isfield(Fig,'ColorMAP')
    Fig.ColorMAP='autumn';
end
if ~isfield(Fig,'ColorRenge')
    try
        Fig.ColorRenge=[min(min(Table.Variables)),max(max(Table.Variables))];
    catch
        Fig.ColorRenge='auto';
    end
end
if ~isfield(Fig,'ColorBar')
    Fig.ColorBar=true;
end
if ~isfield(Fig,'ColorValue')
    try
        Fig.ColorValue=Table.Variables;
        if isstring(Fig.ColorValue)
            Fig.ColorValue=zeros(size(Table));
        end
    catch
        Fig.ColorValue=zeros(size(Table));
    end
end
%% Correct Axis
if isfield(Fig,'Fig')
    figure(Fig.Fig)
else
    figure()
end

if isfield(Fig,'SubFig')
    if length(Fig.SubFig)==3
        subplot(Fig.SubFig{1},Fig.SubFig{2},Fig.SubFig{3})
    else
        subplot(Fig.SubFig)
    end
end

%% Plot Back
Extended=Fig.ColorValue;
Extended(end+1,:)=Extended(end,:);
Extended(:,end+1)=Extended(:,end);
[X,Y]=meshgrid(0:XVarNum,0:YVarNum);
cla
surf(X,Y,Extended,'facealpha',0.5,'edgecolor','k')

view(2);
colormap(Fig.ColorMAP);
caxis(Fig.ColorRenge);
if Fig.TypeValues
    for i=1:YVarNum
        for j=1:XVarNum
            text(Fig.TypeValuesPos{1}(i,j),Fig.TypeValuesPos{2}(i,j),Fig.TypeValuesPos{3},Fig.Text{i,j},'FontSize',Fig.TextSize-2,'HorizontalAlignment','center')
        end
    end
end
if ~isempty(Fig.Title)
    title(Fig.Title,'interpreter','tex')
end
if ~isempty(Fig.YLabel)
    ylabel(Fig.YLabel)
end
if ~isempty(Fig.XLabel)
    xlabel(Fig.XLabel)
end
if Fig.ColorBar
colorbar('Location','eastoutside');
end
ylim([0,YVarNum]);
xlim([0,XVarNum]);
set(gca,'XAxisLocation','top')
set(gca,'YDIR','reverse')
set(gca,'TickLength',[0,0])
xticks(0.5:XVarNum);
yticks(0.5:YVarNum);
xticklabels(Fig.XVarName);
yticklabels(Fig.YVarName);
xtickangle(Fig.XVarNameAngel);
ytickangle(Fig.YVarNameAngel);

%% 
grid off
set(gca,'FontSize',Fig.TextSize)
if isfield(Fig,'Position')
    set(Fig.Fig,'position',Fig.Position);
end